package com.zz.hhbl.config

import android.content.Context
import android.os.Environment
import com.bumptech.glide.Glide
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory
import com.bumptech.glide.module.AppGlideModule
import java.io.File

/**
 * Copyright © 2025 zhun All rights reserved.
 * Created by ZhaoZhun on 2025/2/26 15:02.
 * @author: ZhaoZhun 1820022519@qq.com
 * @version: V1.0
 */

@GlideModule
class GlideCacheModule: AppGlideModule() {
    companion object {
        private const val DISK_CACHE_SIZE = 10*1024 * 1024 * 1024L // 10G
        private const val DISK_CACHE_DIR = "hhby_glide_cache"
    }
    override fun applyOptions(context: Context, builder: GlideBuilder) {
        // 获取自定义的缓存目录
       val  cacheDir = Environment.getExternalStorageDirectory().path + "/Download/${DISK_CACHE_DIR}"
//        val cacheDir = File(context.externalCacheDir, DISK_CACHE_DIR)
//        if (!cacheDir.exists()) {
//            cacheDir.mkdirs()
//        }
        // 设置磁盘缓存路径和大小
        builder.setDiskCache(DiskLruCacheFactory(cacheDir, DISK_CACHE_SIZE))
    }
}
